package com.epsoft.odin7cj.flow.example;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

/**
 * 任务监听
 * @author Administrator
 *
 */
public class T04TaskListen {
	
	public static void main1(String[] args) {
		
		ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
		
		RepositoryService rs = engine.getRepositoryService();
		
		TaskService ts = engine.getTaskService();
		
		RuntimeService rus = engine.getRuntimeService();
		
		Deployment deploy = rs.createDeployment().addClasspathResource("bpmn/t04-task-listener.bpmn").deploy();
		
		ProcessDefinition  pd = rs.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
		
		ProcessInstance pi = rus.startProcessInstanceById(pd.getId()); 
		
		Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		
		// 指定代理人
		//ts.delegateTask(task.getId(), "testHu");
		
		// 完成任务
		ts.complete(task.getId());
		
		System.out.println("\n 任务："+task.getName() ); 
		
		
	}

}
